package com.example.admin.goodnews.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.admin.goodnews.R;
import com.example.admin.goodnews.entity.TuPianLeiBieDataEntity;
import com.example.admin.goodnews.interfaces.RecyclerViewItemClickListener;
import com.example.admin.goodnews.interfaces.RecyclerViewItemLongClickListener;

/**
 * 美图大全页面横向滑动RecyclerView的适配器
 * Created by admin on 2016/10/20.
 */

public class GridViewAdapter extends BaseAdapter {
    private Context context;
    private TuPianLeiBieDataEntity tuPianLeiBieDataEntity;

    public GridViewAdapter(Context context, TuPianLeiBieDataEntity tuPianLeiBieDataEntity) {
        this.context = context;
        this.tuPianLeiBieDataEntity = tuPianLeiBieDataEntity;
    }

    @Override
    public int getCount() {
        return tuPianLeiBieDataEntity.getShowapi_res_body().getLists().size();
    }

    @Override
    public Object getItem(int position) {
        return tuPianLeiBieDataEntity.getShowapi_res_body().getLists().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public View getItemView(int position) {
        return LayoutInflater.from(context).inflate(R.layout.item_gridview_meitudaquan, null);
    }

    public CharSequence getTitle(int position) {
        return tuPianLeiBieDataEntity.getShowapi_res_body().getLists().get(position).getName();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_gridview_meitudaquan, null);
            holder = new ViewHolder();
            holder.tv_main_gridview = (TextView) convertView.findViewById(R.id.tv_main_gridview);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv_main_gridview.setText(tuPianLeiBieDataEntity.getShowapi_res_body().getLists().get(position).getName());
        return convertView;
    }

    public class ViewHolder {
        private TextView tv_main_gridview;
    }
}
